class UserConfirmsController < ApplicationController
  before_action :set_user_confirm, only: [:show, :edit, :update, :destroy]
  before_filter :store_return_url, :only => [:new, :edit]
  respond_to :html
  def index
    @user_confirms = UserConfirm.all
    respond_with(@user_confirms)
  end

  def show
    respond_with(@user_confirm)
  end

  def new
    @user_confirm = UserConfirm.new
    respond_with(@user_confirm)
  end

  def edit
  end

  def create
    @user_confirm = UserConfirm.new(user_confirm_params)
    @user_confirm.save
    redirect_back_or_default(@user_confirm)

  end

  def update
    @user_confirm.update(user_confirm_params)
    redirect_back_or_default(@user_confirm)
  end

  def destroy
    @user_confirm.destroy
    respond_with(@user_confirm)
  end

  protected

  def currentUser
    @user_confirm ||= params[:id].present? ?
    current_user.user_confirms.find(params[:id]) :
    current_user.user_confirms.new(params[:user_confirm])
  end

  def redirect_back_or_default(default)
    case session[:return_to]
    when decide_path then
      redirect_to decide_path(:user_id => currentUser.id)
    when decide_path(:user_id => currentUser.id)
      redirect_to session[:return_to]
    else
      respond_with(default)
    end
  end

  private

  def set_user_confirm
    @user_confirm = UserConfirm.find(params[:id])
  end

  def store_return_url
    store_location(params[:return]) unless params[:return].blank?
  end

  def user_confirm_params
    params.require(:user_confirm).permit(:user_id, :title, :nickname, :email, :fullname, :postcode, :country, :language, :timezone, :gender, :address, :address_additional, :city, :state, :company_name, :job_title, :address_business, :address_additional_business, :postcode_business, :city_business, :state_business, :country_business, :phone_home, :phone_mobile, :phone_work, :phone_fax, :im_aim, :im_icq, :im_msn, :im_yahoo, :im_jabber, :im_skype, :image_default, :biography, :web_default, :web_blog, :dob_day, :dob_month, :dob_year, :deletable)
  end
end
